package com.qfmy.web.app.controller.novel;

import com.qfmy.common.result.Result;
import com.qfmy.model.query.novel.NovelQuery;
import com.qfmy.model.vo.novel.NovelVo;
import com.qfmy.web.app.service.novel.NovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.controller.novel
 * @date 2025/10/31
 * @description 小说
 */
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/novel")
public class NovelController {

    /**
     * 注入 service
     */
    @Autowired
    private NovelService novelService;

    /**
     * 构建分类id获取小说的热门数据
     */
    @RequestMapping("/getHotNovelsByCategoryId")
    public Result<List<NovelVo>> getHotNovels(@RequestParam Integer categoryId) {
        List<NovelVo> list =  novelService.getHotNovels(categoryId);
        return Result.ok(list);
    }


    /**
     * 获取排行榜数据
     */
    @RequestMapping("/getRank")
    public Result<List<NovelVo>> getRank() {
        List<NovelVo> list =  novelService.getRank();
        return Result.ok(list);
    }

    /**
     * 获取限时免费的小说
     */
    @RequestMapping("/getFreeNovels")
    public Result<List<NovelVo>> getFreeNovels() {
        List<NovelVo> list =  novelService.getFreeNovels();
        return Result.ok(list);
    }

    /**
     * 获取评分最高的两个小说
     */
    @RequestMapping("/getTop2ScoreNovels")
    public Result<List<NovelVo>> getTop2ScoreNovels() {
        List<NovelVo> list =  novelService.getTop2ScoreNovels();
        return Result.ok(list);
    }

    /**
     * 获取今日必读的小说
     */
    @RequestMapping("/getTodayMustRead")
    public Result<List<NovelVo>> getTodayMustRead() {
        List<NovelVo> list =  novelService.getTodayMustRead();
        return Result.ok(list);
    }

    /**
     * 分页获取热门完本
     */
    @RequestMapping("/getHotEnd")
    public Result<List<NovelVo>> getHotEnd(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getHotEnd(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 获取新书速通
     */
    @RequestMapping("/getNewBooks")
    public Result<List<NovelVo>> getNewBooks(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getNewBooks(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 获取猜你喜欢的小说
     */
    @RequestMapping("/getGuessLike")
    public Result<List<NovelVo>> getGuessLike(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getGuessLike(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 新书严选
     */
    @RequestMapping("/getNewBooksYanXuan")
    public Result<List<NovelVo>> getNewBooksYanXuan() {
        List<NovelVo> list =  novelService.getNewBooksYanXuan();
        return Result.ok(list);
    }

    /**
     * 获取精品新书
     */
    @RequestMapping("/getJingPinNewBooks")
    public Result<List<NovelVo>> getJingPinNewBooks(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getJingPinNewBooks(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 分页获取免费新书
     */
    @RequestMapping("/getNewFreeNovels")
    public Result<List<NovelVo>> getNewFreeNovels(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getNewFreeNovels(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 获取精选新书
     */
    @RequestMapping("/getJingXuanNewBooks")
    public Result<List<NovelVo>> getJingXuanNewBooks() {
        List<NovelVo> list =  novelService.getJingXuanNewBooks();
        return Result.ok(list);
    }

    /**
     * 获取免费排行榜数据
     */
    @RequestMapping("/getFreeRank")
    public Result<List<NovelVo>> getFreeRank(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getFreeRank(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 获取潜力新书
     */
    @RequestMapping("/getPotentialNewBooks")
    public Result<List<NovelVo>> getPotentialNewBooks(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<NovelVo> list =  novelService.getPotentialNewBooks(pageNum, pageSize);
        return Result.ok(list);
    }

    /**
     * 获取排行榜数据
     */
    @RequestMapping("/getRankByType")
    public Result<List<NovelVo>> getRankByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize,@RequestParam String type) {
        List<NovelVo> list =  novelService.getRankByPage(pageNum, pageSize,type);
        return Result.ok(list);
    }

    /**
     * 根据作者名称获取该作者的所有小说
     */
    @RequestMapping("/getNovelsByAuthorName")
    public Result<List<NovelVo>> getNovelsByAuthorId(@RequestParam String authorName,@RequestParam Integer novelId) {
        List<NovelVo> list =  novelService.getNovelsByAuthorName(authorName,novelId);
        return Result.ok(list);
    }

    /**
     * 分页获取分类的小说
     */
    @RequestMapping("/getNovelsByCategoryId")
    public Result<List<NovelVo>> getNovelsByCategoryId(@RequestParam String tag,@RequestParam Integer pageNum,@RequestParam Integer size) {
        List<NovelVo> list =  novelService.getNovelsByTagsPage(tag,pageNum,size);
        return Result.ok(list);
    }

    /**
     * 搜索小说
     */
    @RequestMapping("/searchBook")
    public Result<List<NovelVo>> searchBook(@RequestParam String keyword)
    {
        List<NovelVo> searchBooks = novelService.searchBook(keyword);
        return Result.ok(searchBooks);
    }

    /**
     * 小说搜索建议
     */
    @RequestMapping("/searchSuggest")
    public Result<List<String>> searchSuggest(@RequestParam String keyword) {
        List<String> list = novelService.searchSuggest(keyword);
        return Result.ok(list);
    }

    /**
     * 获取热读榜
     */
    @RequestMapping("/getHotReadRank")
    public Result<List<NovelVo>> getHotReadRank() {
        List<NovelVo> list =  novelService.getHotReadRank();
        return Result.ok(list);
    }

    /**
     * 获取热评榜
     */
    @RequestMapping("/getHotCommentRank")
    public Result<List<NovelVo>> getHotCommentRank() {
        List<NovelVo> list =  novelService.getHotCommentRank();
        return Result.ok(list);
    }

    /**
     * 更新小说的阅读量
     */
    @RequestMapping("/updateNovelReads")
    public Result updateNovelReads(@RequestParam Integer novelId) {
        novelService.updateNovelReads(novelId);
        return Result.ok();
    }

    /**
     * 更新小说的搜索次数
     */
    @RequestMapping("/updateNovelSearchCount")
    public Result updateNovelSearchCount(@RequestParam Integer novelId) {
        novelService.updateNovelSearchCount(novelId);
        return Result.ok();
    }

    /**
     * 根据Ai获取用户最喜欢一个小说
     */
    @RequestMapping("/getUserLikeNovel")
    public Result<NovelVo> getUserLikeNovel() {
        NovelVo novelVo = novelService.getUserLikeNovel();
        return Result.ok(novelVo);
    }


}
